package com.cx.base.day24_RabbitMQ;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @Author: songyahui
 * @Date: 2020/8/24 19:00
 * @Version 1.0
 */
public class ConnectionUtil {
    public static Connection getConnection() throws Exception {
//        定义连接工厂
        ConnectionFactory factory = new ConnectionFactory();
//        设置服务地址
        factory.setHost("127.0.0.1");
//        端口
        factory.setPort(5672);
//        设置账户信息、用户名、密码、vhost
        factory.setVirtualHost("/shopping");
        factory.setUsername("guest");
        factory.setPassword("guest");
//        通过工程获取连接
        Connection connection = factory.newConnection();
        return connection;


    }

    public static void main(String[] args) throws Exception {
        Connection con = ConnectionUtil.getConnection();
        System.out.println(con);
        if (con != null) {
            con.close();
        }
    }
}
